<template>
  <div class="login">
    <!-- 选项卡区域 -->
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="登录" name="first">
        <el-form ref="form" :model="formLogin" label-width="80px">
          <el-form-item>
            <el-input
              v-model="formLogin.username"
              placeholder="请输入登陆的账号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="formLogin.password"
              placeholder="请输入登陆的密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login(formLogin)" v-preventReClick
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <!-- 验证弹出框区域 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="394px"
      :before-close="handleClose"
    >
      <slide-verify
        :l="42"
        :r="10"
        :w="354"
        :h="155"
        slider-text="向右滑动"
        @success="onSuccess"
        @fail="onFail"
        @refresh="onRefresh"
      ></slide-verify>
      <div>{{ msg }}</div>
    </el-dialog>
  </div>
</template>
<script>
import { request } from "../../api/request";
// import { state } from "@/store/index";
// import { loginMutaions } from "@/store/index";
export default {
  data() {
    return {
      activeName: "first",
      formLogin: { username: "admin", password: "123456" },
      msg: "",
      dialogVisible: false,
      title: "",
    };
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    login() {
      this.onRefresh();
      this.dialogVisible = true;
      this.title = "登录";
    },
    onSuccess() {
      request({
        params: this.formLogin,
        route: "login",
        url: "user",
        method: "post",
        query: null
      }).then((res) => {
        if (res.code === "200") {
          this.$message.success("登陆成功");
          this.$store.commit("user/infoUsername", res);
          // location.reload();
          this.$router.push("/");
        } else {
          this.$message.info(res.msg);
          // this.formLogin = {};
        }
      });
      this.dialogVisible = false;
      this.onRefresh();
    },
    onFail() {
      this.msg = "";
      this.onRefresh();
    },
    onRefresh() {
      this.msg = "";
    },
    handleClose() {
      this.dialogVisible = false;
    },
  },
};
</script>
<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .el-tabs {
    padding: 10px;
    width: 400px;
    height: 227px;
    background-color: #c6e2ff;
    .el-form {
      margin-left: -20px;
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      // margin-top: 50px;
      width: 350px;
      .el-form-item {
        width: 350px;
        .el-input {
          width: 100%;
        }
      }
    }
  }
  .el-dialog {
    margin-top: 50% !important;
  }
}
</style>